package com.ylxl.entity;

import com.ylxl.common.result.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther Gilbert
 * @Date 2023/5/30 21:58
 */
@Data
@Accessors(chain = true)
public class China{
    @ApiModelProperty(value="第一层编码",required = false)
    private String value;
    @ApiModelProperty(value="第一层名称",required = false)
    private String label;
    private List<Two> children;

    public China(Privinces privinces) {
        this.value = privinces.getProvinceCode();
        this.label = privinces.getProvince();
    }

    @Data
    @EqualsAndHashCode(callSuper = false)
    @Accessors(chain = true)
    public static class Two{
        public Two(Cities cities) {
            this.value = cities.getCityCode();
            this.label = cities.getCity();
            this.children = cities.getAreasList().stream().map(Three::new).collect(Collectors.toList());
        }
        @ApiModelProperty(value="第二层编码",required = false)
        private String value;
        @ApiModelProperty(value="第二层名称",required = false)
        private String label;

        private List<Three> children;
    }
    @Data
    @EqualsAndHashCode(callSuper = false)
    @Accessors(chain = true)
    public static class Three{
        public Three(Areas areas) {
            this.value = areas.getRegionCode();
            this.label = areas.getRegion();
        }

        @ApiModelProperty(value="第三层编码",required = false)
        private String value;
        @ApiModelProperty(value="第三层名称",required = false)
        private String label;

    }
}
